﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using BCL.Entity;
using BCL.Repository;


namespace Azad
{

    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "SilverlightService" in code, svc and config file together.
    public class SilverlightService : ISilverlightService
    {
        private NewsRepository newRepo;//= new NewsRepository();
        public SilverlightService()
        {
            newRepo = new NewsRepository();
        }


        public int Activate(int logoInformationId)
        {
            return newRepo.Activate(logoInformationId);
        }

        public int Inactivate(int logoInformationId)
        {
            return newRepo.Inactivate(logoInformationId);
        }


        public int Save(LogoInformation logoInformation)
        {
            return newRepo.Save(logoInformation);
        }

        public int Update(LogoInformation logoInformation)
        {
            return newRepo.Update(logoInformation);
        }

        public LogoInformation Get(int Id)
        {
            return newRepo.Get(Id);
        }
        public LogoInformation GetByCurrentId(DateTime? currentDate, bool isPreview)
        {
            return newRepo.Get(currentDate, isPreview);
        }
        public LogoInformation GetHeadlines()
        {
            return newRepo.GetHeadlines(null, false);
        }

        public int ActivateCommercial(int id)
        {
            return newRepo.ActivateCommercial(id);
        }

        public int InactivateCommercial(int id)
        {
            return newRepo.InactivateCommercial(id);
        }

        public Commercial GetCommercial(int id)
        {
            return newRepo.GetCommercial(id);
        }
        public List<Commercial> GetCommercial(DateTime currentDate)
        {
            return newRepo.GetCommercial(currentDate);
        }

        public List<Commercial> SearchCommercials(String name, int typeId)
        {
            return newRepo.SearchCommercials(name, typeId);
        }

        public int SaveCommercial(Commercial commercial)
        {
            return newRepo.SaveCommercials(new List<Commercial> { commercial });
        }
        public int SaveCommercials(List<Commercial> commercials)
        {
            return newRepo.SaveCommercials(commercials);
        }

        public List<LogoInformation> Search(DateTime? currentDate, int? menuId = null, int to = 0, int from = 1000)
        {
            return newRepo.Search(currentDate, menuId, to, from);
        }

        public List<LookUp> GetMenu()
        {
            LookUpRepository repos = new LookUpRepository();
            var list = repos.GetLookUp("Menu");


            var removed = list.Where(x => x != null && x.Description == "aaj-ka-akhbar").FirstOrDefault();
            list.Remove(removed);
            list.Insert(0, removed);

            return list;
        }

        public List<LookUp> GetTopMenu()
        {
            LookUpRepository repos = new LookUpRepository();
            var list = repos.GetLookUp("Menu1");

            return list;
        }

        public bool AlreadyExist(DateTime currentDate)
        {
            var record = newRepo.Get(currentDate, true);
            if (record != null)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        public List<LogoInformation> ArchiveDate(DateTime? currentDate)
        {
            return newRepo.ArchiveDate(currentDate);
        }
        public List<LookUp> GetCommercialMenu()
        {
            LookUpRepository repos = new LookUpRepository();
            var list = repos.GetLookUp("Commercial");


            var removed = list.Where(x => x != null && x.LookUpID == 11).FirstOrDefault();
            list.Remove(removed);
            list.Insert(0, removed);

            return list;
        }
    }
}